package com.douban.crawl.db;

import com.douban.crawl.model.Book;
import com.douban.crawl.model.Music;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BookDao {

    private BaseDao baseDao = new BaseDao();

    public void save(Book book) {
        baseDao.insert(book);
    }

    public void update(Book book) {
        baseDao.update(book);
    }

    public List<Book> getList() {
        return baseDao.getList(Book.class);
    }

    public List<Book> getList(Integer limitSize) {
        return baseDao.getList(Book.class, limitSize);
    }

    public Book getOne(String bookId) {
        Map<String, String> queryMap = new HashMap<>();
        queryMap.put("book_id", bookId);
        ArrayList<Book> list = baseDao.getList(Book.class, queryMap);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
